package com.nb.controller;

import com.nb.entity.User;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class UserController implements Controller {
    @Override
    public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {

        ModelAndView mv = new ModelAndView();
        ApplicationContext cpx = new ClassPathXmlApplicationContext("springmvc-config.xml");
        User user = cpx.getBean("user", User.class);
        String test = user.getName();
        mv.addObject("msg",test);
        int t2 = user.getAge();
        mv.addObject("msg2",t2);
        mv.setViewName("user");
        return mv;
    }
}
